package swing;
import java.awt.event.ActionEvent;

import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class SwingActionMenuExample extends JFrame{
	
	protected JMenuItem open, save, exit;
	
	protected class MyOpenAction extends AbstractAction{
		
		public MyOpenAction() {
			super("Open...");
		}
		
		public void actionPerformed(ActionEvent e) {
			JFileChooser fileChooser = new JFileChooser();
			fileChooser.showOpenDialog(SwingActionMenuExample.this);
		}
		
	}
	
	protected class MySaveAction extends AbstractAction{
		
		public MySaveAction() {
			super("Save As...");
		}
		
		public void actionPerformed(ActionEvent e) {
			JFileChooser fileChooser = new JFileChooser();
			fileChooser.showSaveDialog(SwingActionMenuExample.this);
		}
		
	}
	protected class MyCloseAction extends AbstractAction{
		
		public MyCloseAction() {
			super("Exit");
		}
		
		public void actionPerformed(ActionEvent e) {
			System.exit(0);
		}
		
	}
		
	public SwingActionMenuExample() {
		setTitle("My Frame"); 
		setSize(400, 150); 		
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);	
		
		JMenu fileMenu = new JMenu("File");
		open = new JMenuItem(new MyOpenAction());
		fileMenu.add(open);
		save = new JMenuItem(new MySaveAction());
		fileMenu.add(save);
		fileMenu.addSeparator();
		exit = new JMenuItem(new MyCloseAction());
		fileMenu.add(exit);
		
		JMenuBar menuBar = new JMenuBar();
		menuBar.add(fileMenu);
		setJMenuBar(menuBar);
				
		setVisible(true); 
	}

	public static void main(String args[]) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
		UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
//		UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
//		UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
//		UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
//		UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsClassicLookAndFeel");
		new SwingActionMenuExample();
	}

}

